<%-- 
    Document   : list_products_search
    Created on : Jan 17, 2013, 2:57:57 PM
    Author     : SONY
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="model.Product"%>
<%@page import="java.util.List"%>
<%@page import="model.ProductService"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<% 
        String keyword = "từ khóa";
        if(request.getAttribute("keyword") != null) {
            keyword = request.getAttribute("keyword").toString();
        }
%>
<table border=0 style="margin-top: 5px;">
	<tr>
            <td>Tìm Kiếm Sản Phẩm</td>
		<td align=center>
                    <form name='frmSearch' method='post' action="<c:url value="/nonmember/search_product.do" />">
			<input type="text" style="margin-bottom: 5px; color: #a4a4a4;" name="keyword" value="<%=keyword%>"/>
			<input type='submit' class="button" name='search' value='Tìm Kiếm'/>
                    </form>
                </td>
	</tr>
</table>
                        <br/>
                        <br/>
<% 
if(request.getAttribute("keyword") != null) {
   ArrayList<Product> products_search = (ArrayList<Product>) request.getAttribute("products_search");
    if(products_search.size() > 0) {
%>
<table border="0" width="650px" cellpadding="10px">        
    <% int col = 0; %>          
    <%        
        for(int i = 0; i < products_search.size(); i++) {
            Product product = (Product) products_search.get(i);
            String pid = product.getProductID();
            String pname = product.getProductName();
            String imgname = product.getImageName();
            int qoh = product.getQOH();
            String qoh_str = "Hết Hàng";
            if(qoh > 0) {
                qoh_str = "Còn Hàng";
            }
            double price = product.getUnitPrice();
    %>
    <% if(col == 0) { %>
        <tr>
    <% } %>

        <td align="center">
        <form method="post" action="./addtocart.do?<%=keyword%>">
            <a href="./product_details.jsp?<%=pid%>"><img src="../images/products/<%=imgname%>" width='130' height='120' title="<%=pname%>"/></a>
            <input type="hidden" name="ImageName" value="<%=imgname%>"/><br/>
            <span style="color:#BE410B;"><%=pname%></span>
            <input type="hidden" name="ProductName" value="<%=pname%>"/><br/>
            <span style="color:#999999;"><%=pid%></span>
            <input type="hidden" name="ProductID" value="<%=pid%>"/><br/>
            <span style="color:#b23b08;font-weight:bold;"><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=price%>"/> đ</span>
            <input type="hidden" name="UnitPrice" value="<%=price%>"/><br/>
            <span style="font-weight:bold;color:#e95b5b;"><%=qoh_str%></span><br/>
            Số Lượng &nbsp;<input type="text" name="quantity"  size=20
                                  value="1" style="text-align: right;width: 50px;margin-bottom: 5px;"/><br/>
            <input type="submit" class="button" value="Chọn Mua"/><br/>
        </form>
        </td>
    <% col++; %>

    <% if(col == 3) { %>
        </tr>
    <% col = 0; } %>
<% } %>       
</table>
<%
if(((HttpServletRequest) request).getAttribute("errorMsg") != null) {
        String errorMsg = ((HttpServletRequest) request).getAttribute("errorMsg").toString();
        if(errorMsg.length() > 0) { 
            out.println("<script type=\"text/javascript\">");
            out.println("alert(\"" + errorMsg + "\")");
            out.println("</script>");
        } 
    }
%> 
<% } else { %>
<p style="font-weight:bold;">Không tìm thấy bất kỳ sản phẩm nào!</p>
<% } 
} else { %>
<p style="font-weight:bold;">Không tìm thấy bất kỳ sản phẩm nào!</p>
<% } %> 
